{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3c80e8b0-9e04-4c5d-8f2e-7ffb3005e976",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "774c2ec9-e38d-4a6b-9540-b3dbc010d982",
   "metadata": {},
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'geopandas'",
     "output_type": "error",
     "traceback": [
      "\u001b[31m---------------------------------------------------------------------------\u001b[39m",
      "\u001b[31mModuleNotFoundError\u001b[39m                       Traceback (most recent call last)",
      "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[1]\u001b[39m\u001b[32m, line 7\u001b[39m\n\u001b[32m      5\u001b[39m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mmatplotlib\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mpyplot\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mas\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mplt\u001b[39;00m\n\u001b[32m      6\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mdatetime\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m datetime, timedelta\n\u001b[32m----> \u001b[39m\u001b[32m7\u001b[39m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mgeopandas\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mas\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mgpd\u001b[39;00m  \u001b[38;5;66;03m# 地理空间分析\u001b[39;00m\n\u001b[32m      9\u001b[39m \u001b[38;5;66;03m# ==== 1. 模拟数据集（20辆车5天的行驶数据） ====\u001b[39;00m\n\u001b[32m     10\u001b[39m \u001b[38;5;66;03m# 设计要点：模拟真实业务场景中的GPS轨迹、速度波动和驾驶事件\u001b[39;00m\n\u001b[32m     11\u001b[39m np.random.seed(\u001b[32m42\u001b[39m)\n",
      "\u001b[31mModuleNotFoundError\u001b[39m: No module named 'geopandas'"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "from sklearn.cluster import DBSCAN  # 基于密度的聚类\n",
    "from sklearn.preprocessing import StandardScaler\n",
    "import matplotlib.pyplot as plt\n",
    "from datetime import datetime, timedelta\n",
    "import geopandas as gpd  # 地理空间分析\n",
    "\n",
    "# ==== 1. 模拟数据集（20辆车5天的行驶数据） ====\n",
    "# 设计要点：模拟真实业务场景中的GPS轨迹、速度波动和驾驶事件\n",
    "np.random.seed(42)\n",
    "num_vehicles = 20\n",
    "days = 5\n",
    "records_per_day = 288  # 5分钟间隔 (24h * 60 / 5)\n",
    "total_records = num_vehicles * days * records_per_day\n",
    "\n",
    "data = {\n",
    "    \"vehicle_id\": np.repeat([f\"V{str(i).zfill(3)}\" for i in range(1, num_vehicles + 1)], days * records_per_day),\n",
    "    \"timestamp\": pd.date_range(\"2025-07-01 00:00:00\", periods=total_records, freq=\"5min\"),\n",
    "    # 速度模拟：正常分布+随机波动（单位：km/h）\n",
    "    \"speed\": np.clip(np.random.normal(65, 15, total_records) + np.random.uniform(-10, 10, total_records), 0, 120),\n",
    "    # 加速度模拟：95%正常范围，5%急加速/急刹车（单位：m/s²）\n",
    "    \"acceleration\": np.where(\n",
    "        np.random.rand(total_records) > 0.05,\n",
    "        np.random.normal(0, 0.8, total_records),\n",
    "        np.random.choice([2.8, -3.2], total_records)\n",
    "    ),\n",
    "    # 地理位置模拟：生成连续轨迹\n",
    "    \"gps_lat\": np.cumsum(np.random.normal(0, 0.001, total_records)),\n",
    "    \"gps_lon\": np.cumsum(np.random.normal(0, 0.001, total_records)),\n",
    "    \"driver_id\": np.random.choice([f\"D{str(i).zfill(3)}\" for i in range(1, 31)], total_records)\n",
    "}\n",
    "df = pd.DataFrame(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "605a92be-f82b-4356-8ad2-c18ccf85840c",
   "metadata": {},
   "outputs": [],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6bd661fe-1c0e-4b3e-93b5-40c2ab9f1f7b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3a423be1-387a-4395-a25c-c2be787502d8",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "932bbb05-ed6b-462e-b69c-102230e1439f",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
